package com.xs.api;

public class Test02 {
    public static void main(String[] args) {
        //String常用的数组
        //1.public int length()获取字符长度;
        String name="我爱你中国love u";
        System.out.println(name.length());
        System.out.println("----------------------");


        //2.public char charAt(int index); 获取某个索引位置的字符
        char c=name.charAt(1);
        System.out.println(c);
        System.out.println("-------遍历字符串的每个字符---------------");
        for (int i = 0; i <name.length() ; i++) {
            char ch=name.charAt(i);
            System.out.println(ch);
        }
        System.out.println("----------------------");


        //3.public char[] tocharArray();  把字符串转换成字符数组
        char[] chars=name.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char ch=chars[i];
            System.out.println(ch);
        }
        System.out.println("----------------------");



        //4 public String substring(int beginIndex,int endIndex);截取内容，包前不包后。
        String name2="java最厉害的编程语言";
        String rs=name2.substring(0,9);
        System.out.println(rs);
        String rs1=name2.substring(4,9);
        System.out.println(rs1);
        System.out.println("----------------------");


        //5 public String substring(int beginIndex);截取内容，从输入的点读取。
        String rs2=name2.substring(5);
        System.out.println(rs2);
        System.out.println("----------------------");


        //6 public String replace(CharSequence target,CharSequence replacement)
        String name3="李鸿辉是我儿子，谭泳麒是我二儿子";
        String r3=name3.replace("李鸿辉","张凌隆");
        System.out.println(r3);
        System.out.println("----------------------");


        //7.public boolean contains(CharSequence s)
        System.out.println(name3.contains("李鸿辉")); //ture
        System.out.println(name3.contains("李2辉")); //false
        System.out.println("----------------------");


        //8.public boolean startsWiths(String prefix)
        System.out.println(name3.startsWith("李鸿辉"));
        System.out.println(name3.startsWith("李鸿辉是我儿子"));
        System.out.println("----------------------");

        //9.public String[] split(String s); 按照某个内容把字符串内容分割成字符返回
        String name4="向硕,张凌隆,谭泳麒,李鸿辉";
        String[] names= name4.split(",");
        for (int i = 0; i <names.length; i++) {
            System.out.println("他们是"+names[i]);
        }
    }

}
